/*
 * File Name:               XReseterChecker.cs
 * 
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>

 * Create Date:             2017/11/14
 */

using System.Collections.Generic;

public interface IReseterChecker<T>
{
    void check(T other, int _index = -1);
}

public class XReseterChecker<T> where T : IReseterChecker<T>
{
    private Queue<T> normalQueue = new Queue<T>(1000);
    public void enqueue_normal(T data)
    {
        normalQueue.Enqueue(data);
    }

    public void enqueue_replay(T data)
    {
        var src = normalQueue.Dequeue();
        src.check(data);
    }
}

//public class MyData : IReseterChecker
//{
//    public struct _MatchInfo
//    {
//        public XNumber matchTimePassed;
//        public int authorId;
//        public MatchStateEnum currentMatchState;

//        public void check(_MatchInfo other)
//        {
//            if (authorId != other.authorId)
//            {
//                Debug.LogErrorFormat("检测到球的控制人信息不一致 {0},{1}", authorId, other.authorId);
//            }

//            if(matchTimePassed != other.matchTimePassed)
//            {
//                Debug.LogError("检测到比赛时间不一致");
//            }

//            if (currentMatchState != other.currentMatchState) Debug.LogError("检测到比赛状态不一致");
//        }

//        public _MatchInfo(GameMatch match)
//        {
//            matchTimePassed = match.matchTimePassed;
//            authorId = match.authorityController == null ? -1 : match.authorityController.ID;
//            currentMatchState = match.CurrentState.myType;
//        }
//    }

//    public struct _BallInfo
//    {
//        public XVector3 position;

//        public void check(_BallInfo other)
//        {
//            if(position != other.position)
//            {
//                Debug.LogError("检测到球的位置信息不一致");
//            }
//        }

//        public _BallInfo(Football ball)
//        {
//            position = ball.position;
//        }
//    }

//    public struct _PlayerInfo
//    {
//        public int id;
//        public XGoalHeadTypeEnum headType;
//        public XVector3 position;
//        public XVector3 renderPosition;
//        public XVector3 lastRenderPosition;
//        public XQuaternion rotation;
//        public XVector3 forward;                            // 面向
//        public PlayerFormationPosition currentLocation; //当前的场上位置;
//        public PlayerFormationPosition runningOriginalLocation; // 当前的运行初始位置
//        public PlayerFormationPosition originalLocation;
//        public int currentAnimationHash;                // 当前动作
//        public XNumber currentAnimationNormalizeTime;       // 当前动作进度
//        public XNumber[] animParameters;                    // 动作参数
//        public XVector3 freemoveTargetPoint;                // 无球跑目标点
//        public XVector3 freemoveTempPoint;                  // 无球跑临时目标点
//        public XVector3 targetForward;                      // 目标方向
//        public XVector3 realVel;                            // 真实速度

//        public _PlayerInfo(Player player)
//        {
//            id = player.ID;
//            headType = player.executionCom.expectGoalType;
//            position = player.position;
//            renderPosition = player.renderPosition;
//            lastRenderPosition = player.lastRenderPosition;
//            rotation = player.rotation;
//            forward = player.forward;
//            currentLocation = player.currentLocation;
//            runningOriginalLocation = player.runningOriginalLocation;
//            originalLocation = player.originalLocation;
//            currentAnimationHash = player.rootAniCtrl.pCurAnimationHash;
//            currentAnimationNormalizeTime = player.rootAniCtrl.pCurNormalizedTime;
//            animParameters = new XNumber[player.animationCom.mParameters.Length];
//            for (int i = 0; i < animParameters.Length; i++)
//            {
//                animParameters[i] = player.animationCom.mParameters[i];
//            }
//            freemoveTargetPoint = player.motionEntity.pMoveTargetPoint;
//            freemoveTempPoint = player.motionEntity.pFreeMoveTempPoint;
//            targetForward = player.motionEntity.targetForward;
//            realVel = player.motionEntity.playerRealVelocity;
//        }

//        public void check(_PlayerInfo other)
//        {
//            if (headType != other.headType) log("顶层目标", headType, other.headType);
//            if (position != other.position) log("位置", position, other.position);
//            if (renderPosition != other.renderPosition) log("renderPosition", renderPosition, other.renderPosition);
//            if (lastRenderPosition != other.lastRenderPosition) log("lastRenderPosition", lastRenderPosition, other.lastRenderPosition);
//            if (rotation != other.rotation) log("旋转", rotation, other.rotation);
//            if (forward != other.forward) log("朝向", forward, other.forward);
//            if (currentLocation != other.currentLocation) log("当前的场上位置", currentLocation, other.currentLocation);
//            if (runningOriginalLocation != other.runningOriginalLocation) log("当前的运行初始位置", runningOriginalLocation, other.runningOriginalLocation);
//            if (originalLocation != other.originalLocation) log("初始的场上位置", originalLocation, other.originalLocation);
//            if (currentAnimationHash != other.currentAnimationHash) log("动作hash", currentAnimationHash, other.currentAnimationHash);
//            if (currentAnimationNormalizeTime != other.currentAnimationNormalizeTime) log("动作进度", currentAnimationNormalizeTime, other.currentAnimationNormalizeTime);
//            for (int i = 0; i < animParameters.Length; i++)
//            {
//                if (animParameters[i] != other.animParameters[i]) log("动画参数" + i, animParameters[i], other.animParameters[i]);
//            }
//            if (freemoveTargetPoint != other.freemoveTargetPoint) log("无球跑目标点", freemoveTargetPoint, other.freemoveTargetPoint);
//            if (freemoveTempPoint != other.freemoveTempPoint) log("无球跑临时目标点", freemoveTempPoint, other.freemoveTempPoint);
//            if (targetForward != other.targetForward) log("目标方向", targetForward, other.targetForward);
//            if (realVel != other.realVel) log("真实速度", realVel, other.realVel);
//        }

//        public void log(string info, object srcValue, object otherValue)
//        {
//            Debug.LogErrorFormat("检测到球员{0}的{1}信息不一致！{2},{3}", id, info, srcValue, otherValue);
//        }

//    }

//    public _MatchInfo matchInfo;
//    public _BallInfo ballInfo;
//    public _PlayerInfo[] playerInfos;

//    public void check<T>(T otherData) where T : IReseterChecker
//    {
//        var other = otherData as MyData;

//        matchInfo.check(other.matchInfo);
//        ballInfo.check(other.ballInfo);
//        for (int i = 0; i < playerInfos.Length; i++)
//        {
//            playerInfos[i].check(other.playerInfos[i]);
//        }
//    }

//    public MyData(MatchLocal_11v11 match)
//    {
//        matchInfo = new _MatchInfo(match);
//        ballInfo = new _BallInfo(match.ball);
//        playerInfos = new _PlayerInfo[match.playerList.Length];
//        for (int i = 0; i < match.playerList.Length; i++)
//        {
//            playerInfos[i] = new _PlayerInfo(match.playerList[i]);
//        }

//    }
//}
